package cn.bs.busuo.content.controller;

import cn.bs.busuo.common.pojo.authentication.CurrentPrincipal;
import cn.bs.busuo.common.web.JsonResult;
import cn.bs.busuo.content.pojo.param.SightArticleAddNewParam;
import cn.bs.busuo.content.pojo.param.TagAddNewParam;
import cn.bs.busuo.content.service.SightArticleService;
import cn.bs.busuo.content.service.TagService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: Feng
 * @since: 2023/12/9
 */
@RestController
@Slf4j
@RequestMapping("/admin/content/sightArticle")
@Api(tags = "4.性格标签")
public class TagController {
    @Autowired
    private TagService tagService;
    @PostMapping("/addNewTag")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("增加性格标签")
    @ApiOperationSupport(order = 100)
    public JsonResult addNewTag(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                         @Valid TagAddNewParam tagAddNewParam) {
        tagService.addNewTag(tagAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/deleteTag")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("删除性格标签")
    @ApiOperationSupport(order = 200)
    public JsonResult deleteTag(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@RequestParam("ids") List<Long> ids) {
        tagService.deleteTag(ids);
        return JsonResult.ok();
    }

    @GetMapping("/selectTagList")
    @PreAuthorize("hasAuthority('/account/user/allInformation')")
    @ApiOperation("查询所有性格标签")
    @ApiOperationSupport(order = 300)
    public JsonResult selectTagList(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        return JsonResult.ok(tagService.selectTagList());
    }
}
